package com.yunshang.ys.base;


import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.support.multidex.MultiDex;
import android.widget.Toast;


import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.yunshang.ys.utils.ComplexUtil;
import com.yunshang.ys.utils.GlideImageLoader;
import com.yunshang.ys.utils.UILImageLoader;
import com.yunshang.ys.ys.YSApplication;

import java.util.LinkedList;
import java.util.List;

import cn.finalteam.galleryfinal.BuildConfig;
import cn.finalteam.galleryfinal.CoreConfig;
import cn.finalteam.galleryfinal.FunctionConfig;
import cn.finalteam.galleryfinal.GalleryFinal;
//import cn.finalteam.galleryfinal.ImageLoader;
import cn.finalteam.galleryfinal.ThemeConfig;


/**
 * Created by Vone (codeofshield@gmail.com) on 2016/10/7.
 * Modify by sa on 2016/12/22
 */

public class BaseApplication extends YSApplication {

//    private static final String TAG = "Init";

//    private static List<Activity> activityList = new LinkedList<>();

    private static Context context;


    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }


    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        ComplexUtil.initialize(getApplicationContext());
        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));
        initgallery();
    }

    private void initgallery() {
        //设置主题
//        ThemeConfig theme = ThemeConfig.CYAN
        ThemeConfig theme = new ThemeConfig.Builder()
                .build();
//配置功能
        FunctionConfig functionConfig = new FunctionConfig.Builder()
                .setEnableCamera(true)
                .setEnableEdit(true)
                .setEnableCrop(true)
                .setEnableRotate(true)
                .setCropSquare(true)
                .setEnablePreview(true)
                .build();

//配置imageloader
        cn.finalteam.galleryfinal.ImageLoader imageloader = new UILImageLoader();
//        ImageLoader imageloader = new GlideImageLoader();
        CoreConfig coreConfig = new CoreConfig.Builder(context, imageloader, theme)
                .setDebug(BuildConfig.DEBUG)
                .setFunctionConfig(functionConfig)
                .build();
        GalleryFinal.init(coreConfig);
    }

    @Override
    public void risInit() {

    }

    @Override
    public void userLoginExpire() {

    }


    //返回系统上下文
    public static Context getAppContext() {
        return context;
    }


    @Override
    public void onLowMemory() {
        super.onLowMemory();
        System.gc();
    }


    @Override
    public void noNetWork() {
        Toast.makeText(context, "网络状态不佳, 请检测网络", Toast.LENGTH_SHORT).show();
    }

}

